import os
from docxtpl import DocxTemplate
class LibreOfficeFile():
    #dirParam = "/Volumes/软件/FHNODE/CRM/myCRM"
    def docToPdf(self,context,filename,dirParam,dirParamTemp):
        doc = DocxTemplate(dirParamTemp+"/"+filename)

        doc.render(context)
        doc.save(dirParam+"/"+filename)
        #filename="DOs_Details_PDFV3.docx"
        return  self.fhLibreOfficeFile(filename,dirParam)

    def fhLibreOfficeFile(self,filename,dirParam):
        #status = 1
        inputdir = dirParam
        outdir =dirParam
        cmdParam ="/Applications/LibreOffice.app/Contents/MacOS/soffice"
        cmd = cmdParam + " --invisible  --convert-to pdf:writer_pdf_Export --outdir " + outdir + "  " + inputdir + "/" + filename
        print("cmd:", cmd)
        status = os.system(cmd)
        if (status == 0):
            print("status:", status)
        return outdir+"/" + filename

'''if __name__ == "__main__":
    LibreOffic = LibreOfficeFile()
    LibreOffic.docToPdf()'''

